package com.jckj.core.service.impl;

import com.jckj.core.dao.NotityAttachementMapper;
import com.jckj.core.entity.NotityAttachementExample;
import com.jckj.core.entity.NotityAttachementKey;
import com.jckj.core.exception.ServiceException;
import com.jckj.core.service.NotifyAttachmentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *     通知附件服务实现类
 * </p>
 * @author :liukuan
 * @date :2018-01-25
 */

@Service
@Transactional(readOnly = true,rollbackFor = ServiceException.class)
public class NotifyAttachmentServiceImpl implements NotifyAttachmentService {

    private static Logger LOGGER = LoggerFactory.getLogger(NotifyAttachmentServiceImpl.class);


    @Autowired
    private NotityAttachementMapper notifyAttachmentMapper;

    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int insertNotifyAttachment(NotityAttachementKey notityAttachementKey) {
        int num=0;
        try {
            num= notifyAttachmentMapper.insertSelective(notityAttachementKey);
        } catch (Exception e) {
            LOGGER.error("增加通知附件中间表:%s", e.fillInStackTrace());
            throw new ServiceException("保存通知附件出错",e);
        }
          return num;
    }


    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int updateByNotifyId(NotityAttachementKey notityAttachementKey,String id) {
          int num=0;
        try {
            NotityAttachementExample example = new NotityAttachementExample();
            NotityAttachementExample.Criteria criteria = example.createCriteria();
            criteria.andNotifyIdEqualTo(id);
            num= notifyAttachmentMapper.updateByExampleSelective(notityAttachementKey,example);
        } catch (Exception e) {
            LOGGER.error("修改通知附件中间表:%s", e.fillInStackTrace());
            throw new ServiceException("修改通知附件出错",e);
        }

        return num;
    }



    @Override
    @Transactional(readOnly = false,rollbackFor = ServiceException.class)
    public int deleteByNotifyId(String id) {
        int num=0;
        try {
            NotityAttachementExample example = new NotityAttachementExample();
            NotityAttachementExample.Criteria criteria = example.createCriteria();
            criteria.andNotifyIdEqualTo(id);
            num=notifyAttachmentMapper.deleteByExample(example);
        } catch (Exception e) {
            LOGGER.error("删除通知附件中间表:%s", e.fillInStackTrace());
            throw new ServiceException("删除通知附件出错",e);
        }
            return num;
    }
}
